package com.example.wordpress;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.app.Activity;
import android.content.Intent;

public class MainActivity extends Activity {

	private Blog blog;
	private MainActivityView mainActivityView;
	private MainActivityCtrl mainActivityCtrl;
	private Database database;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		blog = new Blog();
		database = new Database(this);
		mainActivityView = new MainActivityView(this);
		mainActivityCtrl = new MainActivityCtrl(blog, mainActivityView, database);
		
		((ListView) findViewById(R.id.postList)).setOnItemClickListener(new PostListItemClickListener(mainActivityView));
	}
	
	@Override
	protected void onPause() {
		mainActivityCtrl.onPause();
		super.onPause();
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		mainActivityCtrl.onActivityResult(requestCode, resultCode, data);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return mainActivityView.createOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		return mainActivityCtrl.onOptionsItemSelected(item);
	}
}
